package com.LeeCode;

import java.util.HashMap;

/**
 * 统计一个数组中好对子的数目
 */

public class Code1814 {
    public static void main(String[] args) {
        int[] nums = {13, 10, 35, 24, 76};
        System.out.println(new Code1814().countNicePairs(nums));
    }

    public int countNicePairs(int[] nums) {
        int MOD = 1000000007, ans = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int key = nums[i] - rev(nums[i]);
            if (map.containsKey(key)) {
                ans = (ans + map.get(key)) % MOD;
            }
            map.merge(key, 1, Integer::sum);
        }
        return ans;
    }

    private int rev(int num) {
        int revNum = 0;
        while (num != 0) {
            revNum = revNum * 10 + num % 10;
            num /= 10;
        }
        return revNum;
    }
}
